---
layout: "default"
description: "Swift documentation for 'Encodable'"
keywords: ""
title: "Encodable"
root: "/v5.1"
---

<div class="intro-declaration"><code class="language-swift">protocol Encodable</code></div><p>A type that can encode itself to an external representation.</p>
<table class="standard"><tr><th id="conforming-types">Conforming Types</th><td><code class="inherits">SIMD</code></td></tr></table><div class="discussion comment"></div><h3>Instance Methods</h3><div id="encode_to-8c7f999a44e91e36e6d67e62075ffdbb" class="declaration"><a class="toggle-link" href="#comment-encode_to-8c7f999a44e91e36e6d67e62075ffdbb">func encode(to encoder: Encoder) throws</a> <span class="required">Required</span><div class="comment collapse in" id="comment-encode_to-8c7f999a44e91e36e6d67e62075ffdbb"><p>Encodes this value into the given encoder.</p>
<p>If the value fails to encode anything, <code>encoder</code> will encode an empty
keyed container in its place.</p>
<p>This function throws an error if any values are invalid for the given
encoder's format.</p>
<ul>
<li>Parameter encoder: The encoder to write data to.</li>
</ul>
<h4>Declaration</h4><code class="language-swift">func encode(to encoder: Encoder) throws</code></div></div>